package socket

import (
	"log"
	"net"
)

//ListenShortAdress socket监听短连接
func ListenShortAdress(port string) {
	tcpAdress, err := net.ResolveTCPAddr("tcp", port)
	if err != nil {
		return
	}
	listen, err := net.ListenTCP("tcp", tcpAdress)
	if err != nil {
		return
	}
	defer listen.Close()
	for {
		conn, err := listen.Accept()
		if err != nil {
			continue
		}
		go handldshortFunc(conn)
	}
}

func handldshortFunc(conn net.Conn) {
	defer conn.Close()
	req := make([]byte, 128)
	_, err := conn.Read(req)
	if err != nil {
		log.Println(err)
	}
	log.Println("get mes:", string(req))
	conn.Write([]byte("123"))
}
